﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NFLDriver
{
    //class that stores the team information from the database locally
    //can be used to populate the team names in the UI, or to look up a specific
    //team.
    public class Teams
    {
        private Team[] teams = new Team[32];

        public Teams()
        {

        }
        
        public Team getTeam(int index)
        {
            if((index<32)&&(index>=0))
            {
                return teams[index];
            }
            else
            {
                return null;
            }
        }

        //returns the team with the specified team name;  returns null if no match can be found
        public Team getTeam(string TeamName)
        {
            return searchTeams(TeamName);
        }
        
        public int setTeam(int index, Team team)
        {
            if ((index < 32) && (index >= 0))
            {
                teams[index] = team;
                return 1;
            }
            else
            {
                return 2;
            }
        }

        public int setTeam(int index, string TeamName, int TeamColumn, int score1, int score2, int score3, int score4, int score5, int score6, int score7, int score8, int score9, int score10, int score11, int score12, int score13, int score14, int score15, int score16, int score17)
        {
            if ((index < 32) && (index >= 0))
            {
                teams[index] = new Team(TeamName, TeamColumn, score1, score2, score3, score4, score5, score6, score7, score8, score9, score10, score11, score12, score13, score14, score15, score16, score17);
                return 1;
            }
            else
            {
                return 2;
            }
        }
        
        //searches for a team with a specific team name and returns that team.
        //Due to time constraints, and since this is not a large list, the search will function via bubble search
        private Team searchTeams(string TeamName)
        {
            
            for (int i = 0; i < 17; i++)
            {
                if((String.Compare(teams[i].teamName, TeamName)==0))
                {
                    return teams[i];
                }
            }
            return null;
        }
    }
}
